<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var xhr = new XMLHttpRequest()
        //open的第三个参数设置此次请求是否采用异步方式执行 默认为true异步 false同步
        xhr.open(
              "GET",
              "https://restapi.amap.com/v3/geocode/regeo?location=" +
                123 +
                "," +
                31 +
                "&key=528b8a5595e0dc6ee47f78b82d9c6206",
              true
            );
        //设置请求头
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
        xhr.send()
        xhr.onreadystatechange = (res)=>{
            if (xhr.readyState == 4 && xhr.status == 200) {
                let address = JSON.parse(xhr.responseText)
                console.log("返回的内容",JSON.parse(xhr.responseText).regeocode.formatted_address)
            }
            console.log(xhr.readyState,xhr.status,"哈哈哈哈")
        }
    </script>
</head>
<body>
    <div>XMLHttpRequest-demo</div>
</body>
</html>
